<template>
  <div class="header">
    <HeaderLogo />
    <div class="header-right">
      <div class="header-menu">
        <div
          class="header-menu-item"
          :class="{ 'header-menu-item__active': activeMenu === item.name }"
          v-for="item in appMenus"
          :key="item.name"
          @click="handleClickMenu(item.name)"
        >
          <span>{{ item.label }}</span>
        </div>
      </div>
      <el-button type="primary" @click="handleClickLogin">{{ t('login.signIn') }}</el-button>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import HeaderLogo from './HeaderLogo.vue';
const { t } = useI18n();
defineOptions({
  name: 'AppHeader',
});
const activeMenu = ref('home');
const appMenus = [
  {
    label: t('menu.home'),
    name: 'home',
    path: '/home',
  },
  {
    label: t('menu.features'),
    name: 'features',
    path: '/features',
  },
  {
    label: t('menu.contact'),
    name: 'contact',
    path: '/contact',
  },
];
const router = useRouter();
// 点击菜单跳转指定路由
const handleClickMenu = (name: string) => {
  activeMenu.value = name;
  router.push(appMenus.find((item) => item.name === name)?.path || '/home');
};
// 点击登录
const handleClickLogin = () => {
  router.push('/login');
};
</script>

<style scoped lang="scss">
.header {
  height: 108px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 32px;
  box-sizing: border-box;
  &-logo {
    height: 48px;
    display: flex;
    align-items: center;
    img {
      height: 100%;
    }
    span {
      font-size: 24px;
      margin-left: 16px;
      font-family: 'ShuHeiTi', 'PingFang', sans-serif;
    }
  }
  &-right {
    display: flex;
    align-items: center;
    .header-menu {
      display: flex;
      align-items: center;
      &-item {
        margin-right: 32px;
        font-size: 16px;
        cursor: pointer;
        color: var(--color-text-inactive);
        &__active {
          color: var(--el-color-primary);
        }
        &:hover {
          color: var(--el-color-primary);
        }
      }
    }
  }
}
</style>
